﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace PRJ_LDW_Eutoliso.Account
{
    public partial class Login : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register";
            OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];

            var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
            if (!String.IsNullOrEmpty(returnUrl))
            {

                if (HttpContext.Current.User.IsInRole("Admin"))
                {
                    returnUrl = ("/AccountAdmin/Home.aspx");
                    Response.Redirect(returnUrl);
                }

                if (HttpContext.Current.User.IsInRole("User"))
                {
                    returnUrl = ("/AccountUser/Home.aspx");
                    Response.Redirect(returnUrl);
                }
                
                RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {


            var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
            if (!String.IsNullOrEmpty(returnUrl))
            {

                if (HttpContext.Current.User.IsInRole("Admin"))
                {
                    returnUrl = ("/AccountAdmin/Home.aspx");
                    Response.Redirect(returnUrl);
                }

                if (HttpContext.Current.User.IsInRole("User"))
                {
                    returnUrl = ("/AccountUser/Home.aspx");
                    Response.Redirect(returnUrl);
                }

                //RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
            }
            
            
            
           
        }
    }
}